﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:vw="clr-namespace:VisualWip;assembly=VisualWip"
                    xmlns:vm="clr-namespace:VisualWip.PresentationModel;assembly=PresentationModel"
                    xmlns:Slots="clr-namespace:VisualWip.PresentationModel.Slots;assembly=PresentationModel"
                    xmlns:Uri="clr-namespace:VisualWip.PresentationModel.Uri;assembly=PresentationModel"
                    xmlns:Text="clr-namespace:VisualWip.PresentationModel.Text;assembly=PresentationModel"
                    xmlns:WorkItem="clr-namespace:VisualWip.PresentationModel.WorkItem;assembly=PresentationModel"
                    xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

    <vm:WorkItemSizeTemplateSelector x:Key="workItemSizeTemplateSelector" />
    <vm:NameToImageSourceConverter x:Key="nameToImageConverter" />
    <vm:ColumnTypeToImageResourceConverter x:Key="columnTypeToImageResourceConverter" />
    <vm:AgeInDaysConverter x:Key="ageInDaysConverter" />
    <vm:AgeInMinutesConverter x:Key="ageInMinutesConverter" />
    
    <!-- This is the design for SingleWorkItem column settings -->
    <DataTemplate DataType="{x:Type WorkItem:SingleWorkItemSettingsViewModel}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="150" />
                <ColumnDefinition Width="2" />
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <Label Grid.Row="0" Content="Work item size" />
            <ComboBox Grid.Row="0" Grid.Column="2" Height="23" x:Name="workItemSizeComboBox" ItemsSource="{Binding Sizes}" DisplayMemberPath="Name" SelectedItem="{Binding Size, Mode=TwoWay}" />

            <Label Grid.Row="1" Content="Work item id" />
            <TextBox Grid.Row="1" Grid.Column="2" Text="{Binding WorkItemId, Mode=TwoWay}" MinWidth="200" Width="Auto" />
        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type WorkItem:SingleWorkItemViewModel}">
        <ContentControl Content="{Binding WorkItem}" ContentTemplateSelector="{DynamicResource workItemSizeTemplateSelector}" />
    </DataTemplate>

    <!-- This style is used for animating the column refresh -->
    <Style x:Key="RefreshingCanvasStyle" TargetType="{x:Type Canvas}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsRefreshing}"  Value="True">
                <DataTrigger.EnterActions>
                    <BeginStoryboard x:Name="spinner">
                        <Storyboard RepeatBehavior="Forever">
                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)">
                                <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                <EasingDoubleKeyFrame KeyTime="00:00:00.5000000" Value="180"/>
                                <EasingDoubleKeyFrame KeyTime="00:00:01" Value="359"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>
                    <StopStoryboard BeginStoryboardName="spinner" />
                </DataTrigger.ExitActions>
                <Setter Property="Visibility" Value="Visible" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsRefreshing}" Value="False">
                <Setter Property="Visibility" Value="Hidden" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <!-- This is the work item column  -->
    <DataTemplate DataType="{x:Type WorkItem:WorkColumnViewModel}">
        <Border BorderThickness="2">
            <Grid Style="{DynamicResource WorkItemColumnStyle}">
                <Rectangle x:Name="rectangle1" Style="{DynamicResource ColumnBorderStyle}" />
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Rectangle Grid.Row="0" Style="{DynamicResource ColumnHeaderBackgroundStyle}" >
                    	<Rectangle.Fill>
                    		<LinearGradientBrush EndPoint="1.007,0.525" MappingMode="RelativeToBoundingBox" StartPoint="0.027,0.501">
                    			<GradientStop Color="SkyBlue" Offset="1"/>
                    			<GradientStop Color="#FFACDEEF"/>
                    		</LinearGradientBrush>
                    	</Rectangle.Fill>
                    </Rectangle>
                    <ContentControl Grid.Row="0" x:Name="HeaderContent" Style="{DynamicResource ColumnHeaderContentStyle}" MinHeight="30">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left">
                                <Image Source="{Binding ColumnType, Converter={StaticResource ResourceKey=columnTypeToImageResourceConverter}}" Height="30" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,0,5,0" />
                                <Canvas x:Name="RefreshingCanvas"  Height="24" Width="24" RenderTransformOrigin="0.5,0.5"  Style="{StaticResource RefreshingCanvasStyle}">
                                    <Canvas.RenderTransform>
                                        <TransformGroup>
                                            <RotateTransform/>
                                        </TransformGroup>
                                    </Canvas.RenderTransform>

                                    <Path Data="F1 M 10.000,2.918 C 6.123,2.918 2.964,6.050 2.920,9.917 L 0.002,9.917 C 0.046,4.441 4.514,0.000 10.000,0.000 C 15.487,0.000 19.954,4.441 19.999,9.917 L 17.080,9.917 C 17.036,6.050 13.878,2.918 10.000,2.918 Z" UseLayoutRounding="False" Canvas.Top="1.932" Canvas.Left="1.937">
                                        <Path.Fill>
                                            <LinearGradientBrush MappingMode="Absolute" StartPoint="399.906,240.414" EndPoint="419.903,240.414">
                                                <LinearGradientBrush.Transform>
                                                    <MatrixTransform Matrix="-1.000,0.000,0.000,-1.000,419.905,245.373" />
                                                </LinearGradientBrush.Transform>
                                                <GradientStop Offset="0.26" Color="#ff7f7f7f"/>
                                                <GradientStop Offset="1.00" Color="#ff323232"/>
                                            </LinearGradientBrush>
                                        </Path.Fill>
                                    </Path>
                                    <Path Data="F1 M 17.080,9.917 C 17.080,9.945 17.083,9.972 17.083,10.000 C 17.083,13.904 13.905,17.082 10.000,17.082 C 6.095,17.082 2.917,13.904 2.917,10.000 C 2.917,9.972 2.920,9.945 2.920,9.917 L 0.002,9.917 C 0.002,9.945 0.000,9.972 0.000,10.000 C 0.000,15.514 4.485,20.000 10.000,20.000 C 15.514,20.000 20.000,15.514 20.000,10.000 C 20.000,9.972 19.999,9.945 19.999,9.917 L 17.080,9.917 Z" UseLayoutRounding="False" Canvas.Top="1.932" Canvas.Left="1.937">
                                        <Path.Fill>
                                            <LinearGradientBrush MappingMode="Absolute" StartPoint="489.491,230.414" EndPoint="509.491,230.414">
                                                <LinearGradientBrush.Transform>
                                                    <MatrixTransform Matrix="1.000,0.000,-0.000,-1.000,-489.491,245.373" />
                                                </LinearGradientBrush.Transform>
                                                <GradientStop Offset="0.00" Color="#ffffffff"/>
                                                <GradientStop Offset="0.73" Color="#ff7f7f7f"/>
                                            </LinearGradientBrush>
                                        </Path.Fill>
                                    </Path>
                                </Canvas>
                            </StackPanel>
                            <TextBlock Grid.Column="1" Margin="2" FontSize="12" TextAlignment="Center" TextWrapping="Wrap" Text="{Binding ColumnName}" FontWeight="Bold" />
                            <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="2">
                                <TextBlock FontSize="18" FontWeight="Bold" Text="{Binding WorkInProgress}" Style="{DynamicResource ResourceKey=WorkInProgressTextStyle}" />
                                <TextBlock FontSize="18" Text=" of " Style="{DynamicResource ResourceKey=WorkInProgressLimitTextStyle}" />
                                <TextBlock FontSize="18" FontWeight="Bold" Text="{Binding WorkInProgressLimit}" Style="{DynamicResource ResourceKey=WorkInProgressLimitTextStyle}" />
                            </StackPanel>
                        </Grid>
                    </ContentControl>
                    <ItemsControl Grid.Row="1" ItemsSource="{Binding Slots}" ItemTemplate="{DynamicResource SlotView}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <!-- The column slots will be added here -->
                                <WrapPanel HorizontalAlignment="Left" VerticalAlignment="Top" IsItemsHost="True" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </Grid>
            </Grid>
        </Border>
    </DataTemplate>

    <!-- This style is for the work-in-progres limit text -->
    <Style x:Key="WorkInProgressLimitTextStyle" TargetType="{x:Type TextBlock}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding HasWorkInProgressLimit}" Value="False" >
                <Setter Property="Visibility" Value="Collapsed" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <!-- This style is for the actual work-in-progres text -->
    <Style x:Key="WorkInProgressTextStyle" TargetType="{x:Type TextBlock}">
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding HasWorkInProgressLimit}" Value="True" />
                    <Condition Binding="{Binding IsOverWorkInProgressLimit}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Foreground" Value="Red" />
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>

    <!-- This is the work-in-progress group column  -->
    <DataTemplate DataType="{x:Type WorkItem:WorkInProgressGroupViewModel}">
        <Border BorderThickness="2">
            <Grid Style="{DynamicResource WorkItemColumnStyle}">
                <Rectangle Style="{DynamicResource ColumnBorderStyle}"/>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Rectangle Grid.Row="0" Style="{DynamicResource ColumnHeaderBackgroundStyle}" />
                    <ContentControl Grid.Row="0" x:Name="HeaderContent" Style="{DynamicResource ColumnHeaderContentStyle}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="1" Margin="2" FontSize="12" TextAlignment="Center" TextWrapping="Wrap" Text="{Binding ColumnName}" FontWeight="Bold" />
                            <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="2">
                                <TextBlock FontSize="18" FontWeight="Bold" Text="{Binding WorkInProgress}">
                                      <TextBlock.Style>
                                        <Style TargetType="{x:Type TextBlock}">
                                          <Style.Triggers>
                                            <MultiDataTrigger>
                                              <MultiDataTrigger.Conditions>
                                                <Condition Binding="{Binding HasWorkInProgressLimit}" Value="True" />
                                                <Condition Binding="{Binding IsOverWorkInProgressLimit}" Value="True" />
                                              </MultiDataTrigger.Conditions>
                                              <Setter Property="Foreground" Value="Red" />
                                            </MultiDataTrigger>
                                          </Style.Triggers>
                                        </Style>
                                      </TextBlock.Style>
                                </TextBlock>
                                <TextBlock FontSize="18" Text="/" />
                                <TextBlock FontSize="18" FontWeight="Bold" Text="{Binding WorkInProgressLimit}" />
                            </StackPanel>
                        </Grid>
                    </ContentControl>
                </Grid>
            </Grid>
        </Border>
    </DataTemplate>

    <!-- This style is for setting the column background based on the work-in-progress limits and actual work -->
    <Style x:Key="WorkItemColumnStyle" TargetType="{x:Type Grid}">
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding HasWorkInProgressLimit}" Value="True" />
                    <Condition Binding="{Binding IsOverWorkInProgressLimit}" Value="True" />
                    <Condition Binding="{Binding ShowWorkInProgressLimit}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Background" Value="LightCoral" />
            </MultiDataTrigger>

            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding HasWorkInProgressLimit}" Value="True" />
                    <Condition Binding="{Binding IsAtWorkInProgressLimit}" Value="True" />
                    <Condition Binding="{Binding ShowWorkInProgressLimit}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Background" Value="LightYellow" />
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>

    <!-- This is the slot. Columns contains slots that can contain work items  -->
    <DataTemplate x:Key="SlotView">
        <Border BorderThickness="2">
            <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
                <Grid.RowDefinitions>
                    <RowDefinition Height="100*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Rectangle Grid.Row="0" x:Name="slotBorder" Style="{DynamicResource SlotBorderStyle}" StrokeThickness="4" RadiusX="5" RadiusY="5" />
                <TextBlock Grid.Row="0" Text="Empty" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" FontSize="24" FontWeight="Bold" Foreground="#19ADD8E6" />
                <Border Grid.Row="0" BorderThickness="5">
                    <ContentControl x:Name="slotContentControl" Content="{Binding WorkItem}" ContentTemplateSelector="{DynamicResource workItemSizeTemplateSelector}" />
                </Border>
                <TreeView Grid.Row="1" ItemsSource="{Binding WorkItem.Children}" BorderBrush="{x:Null}" Background="{x:Null}">
                    <TreeView.Resources>
                        <ResourceDictionary>
                            <HierarchicalDataTemplate DataType="{x:Type WorkItem:WorkItemViewModel}" ItemsSource="{Binding Children}" />
                        </ResourceDictionary>
                    </TreeView.Resources>
                </TreeView>
            </Grid>
        </Border>
    </DataTemplate>

    <!-- This sets the border for the slot based on slot type and work-in-progress limit -->
    <Style x:Key="SlotBorderStyle" TargetType="{x:Type Rectangle}">
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding HasWorkInProgressLimit}" Value="True" />
                    <Condition Binding="{Binding IsInWorkInProgressLimit}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Stroke" Value="Black" />
            </MultiDataTrigger>
            <DataTrigger Binding="{Binding IsAvailableSlot}" Value="False">
                <Setter Property="StrokeDashArray" Value="2,1" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <!-- This is the design for a large work item -->
    <DataTemplate x:Key="LargeWorkItemView">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="75" />
            </Grid.ColumnDefinitions>
            <Image Grid.Column="1" Height="75" Width="75" Source="{Binding Fields[Assigned To], Converter={StaticResource nameToImageConverter}, Mode=OneWay}" HorizontalAlignment="Right" VerticalAlignment="Bottom" Opacity="0.65" Panel.ZIndex="10">
                <Image.RenderTransform>
                    <TransformGroup>
                        <RotateTransform Angle="-1" />
                        <TranslateTransform X="5" Y="5" />
                    </TransformGroup>
                </Image.RenderTransform>
            </Image>
            <Border Grid.ColumnSpan="2" BorderThickness="2" Width="230" Height="150" vm:MouseBehavior.DoubleClick="{Binding OpenCommand}" Style="{DynamicResource WorkItemChangedBorderStyle}">
                <Grid x:Name="WorkItem" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="100*" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Canvas Margin="1,2,73,0" Height="31" VerticalAlignment="Top" d:IsLocked="True">
                        <Path Data="M19.198454,100.1851 L11.987272,153.53848 90.258018,155.0154 86.998783,100.09202 z" Stretch="Fill" UseLayoutRounding="False" StrokeThickness="0.5" Fill="Black" Height="126.285" Canvas.Left="2.716" Canvas.Top="18" Width="215.247" d:IsLocked="True">
                            <Path.Effect>
                                <DropShadowEffect Opacity="0.37" Direction="675" ShadowDepth="12"/>
                            </Path.Effect>
                        </Path>
                        <Border UseLayoutRounding="False" BorderThickness="0.5" BorderBrush="#FFEBE490" Height="146.433" Width="220" Style="{DynamicResource WorkItemTypeBorderStyle}" d:IsLocked="True"/>
                    </Canvas>
                    <WrapPanel x:Name="headingPanel" HorizontalAlignment="Stretch" Height="Auto" Margin="5" VerticalAlignment="Stretch" Width="Auto">
                        <TextBlock x:Name="heading" MaxHeight="100" Text="{Binding Heading}" FontSize="18" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" />
                    </WrapPanel>

                    <WrapPanel x:Name="descriptionPanel"  HorizontalAlignment="Stretch" Margin="5,0,5,0" Grid.Row="1" VerticalAlignment="Stretch">
                        <TextBlock x:Name="descriptionTextBlock" Text="{Binding Fields[Description]}" TextWrapping="Wrap" />
                    </WrapPanel>
                    <WrapPanel x:Name="assignedToPanel" HorizontalAlignment="Center" Margin="5,0,5,0" Grid.Row="2" VerticalAlignment="Stretch">
                        <TextBlock x:Name="assignedToTextBlock" Text="{Binding Fields[Assigned To]}" TextWrapping="Wrap" />
                    </WrapPanel>
                    <WrapPanel x:Name="datesPanel" HorizontalAlignment="Stretch" Margin="5,0,5,0" Grid.Row="3" VerticalAlignment="Stretch">
                        <Image Style="{DynamicResource WorkItemAgeImageStyle}" Width="16" Height="16" Margin="2,0,2,0" VerticalAlignment="Bottom" d:IsLocked="True" />
                        <TextBlock x:Name="createdTextBlock" Text="{Binding Fields[Created Date], StringFormat=d}" TextWrapping="Wrap" d:IsLocked="True" />
                    </WrapPanel>
                </Grid>
            </Border>
        </Grid>
    </DataTemplate>

    <!-- This is the design for a medium work item -->
    <DataTemplate x:Key="MediumWorkItemView">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="75" />
            </Grid.ColumnDefinitions>
            <Image Grid.Column="1" Height="75" Width="75" Source="{Binding Fields[Assigned To], Converter={StaticResource nameToImageConverter}, Mode=OneWay}" HorizontalAlignment="Right" VerticalAlignment="Bottom" Opacity="0.65" Panel.ZIndex="10">
                <Image.RenderTransform>
                    <TransformGroup>
                        <RotateTransform Angle="-1" />
                        <TranslateTransform X="5" Y="5" />
                    </TransformGroup>
                </Image.RenderTransform>
            </Image>
            <Border Grid.ColumnSpan="2" BorderThickness="2" Width="230" Height="75" vm:MouseBehavior.DoubleClick="{Binding OpenCommand}" Style="{DynamicResource WorkItemChangedBorderStyle}">            	
                <Grid x:Name="WorkItem">  
                	 <Canvas Margin="1,2,73,0" Height="31" VerticalAlignment="Top">
                        <Path Data="M19.198454,100.1851 L11.987272,153.53848 90.258018,155.0154 88.08968,101.10457 z" Stretch="Fill" UseLayoutRounding="False" StrokeThickness="0.5" Fill="Black" Height="58.917" Canvas.Left="2.716" Canvas.Top="8.512" Width="215.247">
                            <Path.Effect>
                                <DropShadowEffect Opacity="0.37" Direction="675" ShadowDepth="9"/>
                            </Path.Effect>
                        </Path>
                        <Border UseLayoutRounding="False" BorderThickness="0.5" BorderBrush="#FFEBE490" Height="68.433" Width="220" Style="{DynamicResource WorkItemTypeBorderStyle}"/>
                    </Canvas>                	
                    <WrapPanel x:Name="contentPanel" HorizontalAlignment="Stretch" Margin="5,0,5,0" Grid.Row="3" VerticalAlignment="Stretch">
                        <TextBlock x:Name="heading" Text="{Binding Heading}" FontSize="18" TextWrapping="Wrap" TextAlignment="Left" VerticalAlignment="Top" />
                        <TextBlock x:Name="description" Text="{Binding Fields[Description]}" FontSize="12" TextWrapping="Wrap" TextAlignment="Left" VerticalAlignment="Top" />
                    </WrapPanel>
                </Grid>
            </Border>
        </Grid>
    </DataTemplate>

    <!-- This is the design for a small work item -->
    <DataTemplate x:Key="SmallWorkItemView">
        <Border BorderThickness="2" Width="100" Height="40" vm:MouseBehavior.DoubleClick="{Binding OpenCommand}" Style="{DynamicResource WorkItemChangedBorderStyle}">
            <Grid x:Name="WorkItem">      
            	<Canvas Margin="1,2,73,0" Height="31" VerticalAlignment="Top">
                        <Path Data="M19.198454,100.1851 L11.987272,153.53848 90.258018,155.0154 86.104912,101.97362 z" Stretch="Fill" UseLayoutRounding="False" StrokeThickness="0.5" Fill="Black" Height="29.645" Canvas.Left="1.16" Canvas.Top="4.283" Width="91.97">
                            <Path.Effect>
                                <DropShadowEffect Opacity="0.37" Direction="675"/>
                            </Path.Effect>
                        </Path>
                        <Border UseLayoutRounding="False" BorderThickness="0.5" BorderBrush="#FFEBE490" Height="34.433" Width="94" Style="{DynamicResource WorkItemTypeBorderStyle}"/>
                    </Canvas>             
                <WrapPanel x:Name="contentPanel" HorizontalAlignment="Stretch" Margin="5,0,5,0" Grid.Row="3" VerticalAlignment="Stretch">
                    <TextBlock x:Name="heading" Text="{Binding Id}" FontSize="18" TextWrapping="Wrap" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" />
                </WrapPanel>
            </Grid>
        </Border>
    </DataTemplate>

    <LinearGradientBrush x:Key="YellowGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFFF4C8" Offset="0.277"/>
                    <GradientStop Color="#FFEBE490" Offset="1"/>
    </LinearGradientBrush>
	
	 <LinearGradientBrush x:Key="RedGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFBE3E3" Offset="0.277"/>
                    <GradientStop Color="#FFF9ABAB" Offset="1"/>
    </LinearGradientBrush>

	 <LinearGradientBrush x:Key="OrangeGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFF1D9A4" Offset="0.277"/>
                    <GradientStop Color="#FFFDB346" Offset="1"/>
    </LinearGradientBrush>

 	<LinearGradientBrush x:Key="LightBlueGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFD3E8EB" Offset="0.277"/>
                    <GradientStop Color="#FF9FCCE4" Offset="1"/>
    </LinearGradientBrush>

	 <LinearGradientBrush x:Key="LightGreenGradient" EndPoint="0.5,1" StartPoint="0.5,0">
	 	<GradientStop Color="#FFE0F3D1" Offset="0.277"/>
	 	<GradientStop Color="#FFBFE284" Offset="1"/>
	 </LinearGradientBrush>

    <LinearGradientBrush x:Key="GreenGradient" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FFB9CEA8" Offset="0.277"/>
        <GradientStop Color="#FF598F46" Offset="1"/>
    </LinearGradientBrush>

    <!-- This style sets the background color for work item based on the work item type -->
    <Style x:Key="WorkItemTypeBorderStyle" TargetType="{x:Type Border}">
        <Setter Property="Background" Value="{StaticResource YellowGradient}" />

        <Style.Triggers>
            <DataTrigger Binding="{Binding TypeName}" Value="NoWorkItem">
                <Setter Property="Background" Value="Transparent" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="ErrorWorkItem">
                <Setter Property="Background" Value="{StaticResource RedGradient}" />
            </DataTrigger>

            <DataTrigger Binding="{Binding TypeName}" Value="User Story">
                <Setter Property="Background" Value="{StaticResource YellowGradient}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="Product Backlog Item">
                <Setter Property="Background" Value="{StaticResource YellowGradient}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="Change Request">
                <Setter Property="Background" Value="{StaticResource YellowGradient}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="Requirement">
                <Setter Property="Background" Value="{StaticResource LightGreenGradient}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="Issue">
                <Setter Property="Background" Value="{StaticResource RedGradient}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="Impediment">
                <Setter Property="Background" Value="{StaticResource RedGradient}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="Risk">
                <Setter Property="Background" Value="{StaticResource RedGradient}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="Bug">
                <Setter Property="Background" Value="{StaticResource OrangeGradient}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TypeName}" Value="Task">
                <Setter Property="Background" Value="{StaticResource LightBlueGradient}" />
            </DataTrigger>

        </Style.Triggers>
    </Style>



    <!-- This style sets border background color based on how long since the last change -->
    <Style x:Key="WorkItemChangedBorderStyle" TargetType="{x:Type Border}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Fields[Changed Date], ConverterParameter=0, Converter={StaticResource ageInMinutesConverter}}" Value="true">
                <Setter Property="Background" Value="{StaticResource RedGradient}" />
            </DataTrigger>

            <DataTrigger Binding="{Binding Fields[Changed Date], ConverterParameter=1, Converter={StaticResource ageInMinutesConverter}}" Value="true">
                <Setter Property="Background" Value="{StaticResource YellowGradient}" />                
            </DataTrigger>

            <DataTrigger Binding="{Binding Fields[Changed Date], ConverterParameter=2, Converter={StaticResource ageInMinutesConverter}}" Value="true">
                <Setter Property="Background" Value="{StaticResource GreenGradient}" />
            </DataTrigger>

            <DataTrigger Binding="{Binding Fields[Changed Date], ConverterParameter=5, Converter={StaticResource ageInMinutesConverter}}" Value="true">
                <Setter Property="Background" Value="Transparent" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <!-- This style sets the age image based on the work item age since creation -->
    <Style x:Key="WorkItemAgeImageStyle" TargetType="{x:Type Image}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Fields[Created Date], ConverterParameter=5, Converter={StaticResource ageInDaysConverter}}" Value="true">
                <Setter Property="Source" Value="\Images\109_AllAnnotations_Info_32x32_72.png" />
            </DataTrigger>

            <DataTrigger Binding="{Binding Fields[Created Date], ConverterParameter=10, Converter={StaticResource ageInDaysConverter}}" Value="true">
                <Setter Property="Source" Value="\Images\109_AllAnnotations_Warning_32x32_72.png" />
            </DataTrigger>

            <DataTrigger Binding="{Binding Fields[Created Date], ConverterParameter=20, Converter={StaticResource ageInDaysConverter}}" Value="true">
                <Setter Property="Source" Value="\Images\109_AllAnnotations_Error_32x32_72.png" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <!-- This style is for the parent child tree view of work items -->
    <Style TargetType="{x:Type TreeViewItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ContentPresenter x:Name="WorkItemChild" ContentSource="Header" ContentTemplateSelector="{StaticResource workItemSizeTemplateSelector}" HorizontalAlignment="Right" VerticalAlignment="Top" />
                        <ItemsPresenter Grid.Row="2" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <StackPanel IsItemsHost="True" Orientation="Vertical" Margin="0,0,0,5" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>